package com.chenjun.designpattern.creational.factory;

public class 简单工厂模式
{
	public static void main(String[] args)
	{
		SampleFactory factory = new SampleFactory();
		Sample sample = factory.getSample(SampleA.class);
		sample.print();
	}
}

class SampleFactory
{
	public Sample getSample(Class<?> clazz)
	{
		if ( clazz.equals(SampleA.class) )
		{
			return new SampleA();
		}
		else
		{
			return new SampleB();
		}
	}
}

abstract class Sample
{
	public abstract void print();
}

class SampleA extends Sample
{

	@Override
	public void print()
	{
		System.out.println("sample A");
	}

}

class SampleB extends Sample
{

	@Override
	public void print()
	{
		System.out.println("sample B");
	}
}